

// Schema  数据结构 
// Schema主要用于定义MongoDB中集合Collection里文档document的结构
// 不仅仅可以定义文档的结构和属性，还可以定义文档的实例方法、静态模型方法、复合索引等
// 每个schema会映射到mongodb中的一个collection，schema不具备操作数据库的能力



// 定义Schema非常简单，指定字段名和类型即可
// String      字符串
// Number      数字    
// Date        日期
// Buffer      二进制
// Boolean     布尔值
// Mixed       混合类型
// ObjectId    对象ID    
// Array       数组
var mongoose = require("mongoose")
var Schema = mongoose.Schema;

var user_schema = new Schema({
    username:String,
    age:Number,
    password:String,
    nikename:String,
    phone:String
})



// model 数据模型  
// Model是由Schema编译而成的假想（fancy）构造器  具有抽象属性和行为
// Model 可以保存到数据库和对数据库进行操作   model是由schema生成的模型，可以对数据库的操作。

// mongoose.model(`文档名称`, Schema)  

// Mongoose会将集合名称设置为模型名称的小写版。如果名称的最后一个字符是字母，则会变成复数；如果名称的最后一个字符是数字，则不变；如果模型名称为"MyModel"，则集合名称为"mymodels"；如果模型名称为"Model1"，则集合名称为"model1"


exports.UsersModel = mongoose.model('users',user_schema);


// movie  
var movie_schema = new Schema({
    "genres": Array,
    "casts": Array,
    "directors": Array,
    "rating": Object,
    "title": String,
    "collect_count": Number,
    "original_title": String,
    "subtype": String,
    "year": String,
    "images": Object,
    "alt": String,
    "id": String
})

exports.MovieModel = mongoose.model("movies",movie_schema)




var whusers_schema = new Schema({
    username:String,
    phone:String,
    nickname:String,
    age:Number,
    pass:String,
    time:Date 
})

exports.WhuserModel = mongoose.model("whusers",whusers_schema)



var comment_schema = new Schema({
    title:String,
    content:String,
    time:Date,
    author:String,
    movie:Object,
    mid:String
})

exports.CommentModel = mongoose.model("comments",comment_schema)




var mzuser_schema = new Schema({
    username:String,
    phone:String,
    nickname:String,
    age:Number,
    password:String,
    dbpass:String,
    time:Date,
    avatar:String
})

exports.mzusersModel = mongoose.model("mzusers",mzuser_schema)


var shopcar_schema = new Schema({
    username:String,
    phone:String,
    time:Date,
    gid:String,
    good:Object,
    count:Number,
    check:Boolean
})

exports.ShopCarModel = mongoose.model("shopcars",shopcar_schema)


var liuyan_schema = new Schema({
    title:String,
    content:String,
    time:Date
})

exports.LiuYanModel = mongoose.model("liuyans",liuyan_schema)


var adminuser_schema = new Schema({
    phone:String,
    password:String,
    username:String,
    avatar:String,
    time:Date,
    role:Number  // 角色 权限  0  普通用户  1 管理员  2 超级管理员  3 老板 
})

exports.adminusers = mongoose.model("adminusers",adminuser_schema)



var anno_schema = new Schema({
    title:String,
    content:String,
    time:Date,
    author:String,
    category:String,
    img:String,
    count:Number,
    avatar:String
})

exports.adminannos = mongoose.model("annos",anno_schema)


var advise_schema = new Schema({
    title:String,
    content:String,
    time:Date,
    author:String,
    category:Array,
    avatar:String,
    comments:Array
})

exports.adminadvise = mongoose.model("advises",advise_schema)